package com.sheep.jucdemo.part11.part11_10;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Date 2022/5/31 22:21
 * @Created by sheep
 */
public class Test11_10_2 {
    static class LocalVariable {
        private Long[] a = new Long[1024*1024];
     }
     // （1）
    final static ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(5,5,1, TimeUnit.MINUTES,new LinkedBlockingDeque<>());
    // （2）
    final static ThreadLocal<LocalVariable> localVariable = new ThreadLocal<LocalVariable>();

    public static void main(String[] args) throws InterruptedException {
        // （3）
        for (int i = 0; i < 50; i++) {
            poolExecutor.execute(new Runnable() {
                @Override
                public void run() {
                    // （4）
                    localVariable.set(new LocalVariable());
                    // （5）
                    System.out.println("use local varaible");
                    //localVariable.remove();
                }
            });
            Thread.sleep(1000);
        }
        // （6）
        System.out.println("pool execute over");
    }

}
